<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2016/8/11
 * Time: 下午2:48
 */

namespace Home\Model;
use Think\Model;
/**
 * Class ScoreModel
 * @package Home\Model
 * CREATE TABLE `yiyuan_snsnb_com`.`hospital_hospital_score` (
 * `score_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
 * `score_score` TINYINT UNSIGNED NOT NULL,
 * `score_comment` CHAR(50) NOT NULL,
 * `user_name` CHAR(10) NOT NULL,
 * `user_avator` CHAR(50) NOT NULL,
 * `hospital_id` INT UNSIGNED NOT NULL,
 * `user_id` INT UNSIGNED NOT NULL,
 * `vid` INT UNSIGNED NOT NULL,
 * `score_create_time` INT UNSIGNED NOT NULL,
 * PRIMARY KEY (`score_id`))
 * ENGINE = MyISAM
 * DEFAULT CHARACTER SET = utf8;
 */
class ScoreModel extends Model
{
    protected $tableName = 'hospital_score';
    public static function insert($score,$comment,$hospitalID,$userID,$userName,$userAvator,$vid)
    {
        $data = array(
            'score_score' => (int)$score,
            'score_comment' => $comment,
            'hospital_id' => $hospitalID,
            'user_id' => $userID,
            'user_name' => $userName,
            'user_avator' => $userAvator,
            'score_create_time' => time(),
            'vid' => $vid,
        );
        $object = new static();
        return $object->add($data);
    }

    public static function getScoreByHospitalID($hospitalID,$page = 1,$pageSize = 10)
    {
        $object = new static();
        $start = ($page * $pageSize) - $pageSize;
        $scores = $object->where(array('hospital_id' => $hospitalID))->order('score_create_time asc')->limit($start, $pageSize)->select();
        return $scores;
    }
}